<?php

namespace App\Http\Controllers\Api\Plane;

use App\Http\Controllers\Controller;
use App\Http\Resources\Plane\PlaneOrder\PlaneOrderResource;
use App\Models\Plane\PlaneOrderPassengers\Repositories\Interfaces\PlaneOrderPassengerRepositoryInterface;
use App\Models\Plane\PlaneOrders\Repositories\Interfaces\PlaneOrderRepositoryInterface;
use Illuminate\Http\Request;

/**
 * 主要处理 改签待核算价格回填
 */
class PlaneChangePriceController extends Controller
{
    private PlaneOrderRepositoryInterface          $planeOrderRepo;
    private PlaneOrderPassengerRepositoryInterface $orderPassengerRepo;

    public function __construct(
        PlaneOrderRepositoryInterface          $planeOrderRepo,
        PlaneOrderPassengerRepositoryInterface $orderPassengerRepo
    )
    {
        $this->planeOrderRepo     = $planeOrderRepo;
        $this->orderPassengerRepo = $orderPassengerRepo;
    }


    public function changing_checking_list(Request $request)
    {
        // 获取价格待核算的订单
    }

    public function refill_price(Request $request)
    {
        // 这里只能获取到原单订单
        $order_info = $this->orderPassengerRepo->getOrderInfoBySubOutOrderId($request->input('sub_out_order_id', ''));
        $changing   = $this->planeOrderRepo->getChangingOrders([
            'origin_order_sn'      => $order_info->getOrderSn(),
            'provider_price_state' => 0,
        ]);

        $order = $this->planeOrderRepo->refillChangingConfirmPrice($changing->first(), $request->only([
            'change_fee',
            'upgrade_fee',
            'sub_out_order_id',
        ]));

        return $this->success('', [
            'order_info' => new PlaneOrderResource($order),
        ]);
    }
}